<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Get (Advanced) : DataMapper ORM - User Guide</title>

<link rel="shortcut icon" type="image/png" href="../images/favicon.png" />
<link rel="stylesheet" type="text/css" media="all" href="../css/userguide.css" />
<link rel="alternate" type="application/rss+xml" title="Datamapper ORM Updates Feed" href="/rss.xml" />

<meta http-equiv="expires" content="-1" />
<meta http-equiv= 'pragma' content="no-cache" />
<meta name="robots" content="all" />

</head>

<body>

<!-- START NAVIGATION -->
<div id="nav"><div id="nav_inner"></div></div>
<div id="nav2"><a name="top">&nbsp;</a><a id="nav_toggle" href="#"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
<div id="masthead">
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
<td><h1>DataMapper ORM</h1></td>
<td id="breadcrumb_right"><a href="toc.html">Table of Contents Page</a></td>
</tr>
</table>
</div>
<!-- END NAVIGATION -->

<!-- START BREADCRUMB -->
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
<td id="breadcrumb">
<a href="/">Datamapper ORM Home</a> &nbsp;&#8250;&nbsp;
<a href="../index.html">User Guide Home</a> &nbsp;&#8250;&nbsp;
Get (Advanced)
</td>
</tr>

</table>
<!-- END BREADCRUMB -->

<br clear="all" />


<!-- START CONTENT -->
<div id="content">

<h1 id="Get.Advanced"> Get (Advanced)</h1>

<p>DataMapper has extended versions of most of its query clauses that allow for advanced querying on relationships.</p>

<h4>Subsections</h4>
<ul>
	<li><a href="#Get.Advanced">Get (Advanced)</a> (This Section)
		<ul>
			<li><a href="#Get.Advanced.Example">Example</a></li>
			<li><a href="#Supported.Query.Clauses">Supported Query Clauses</a></li>
			<li><a href="#_related_model">Query Related Models (Known Model Name)</a></li>
			<li><a href="#_related">Query Related Models (Dynamic Model Name)</a></li>
			<li><a href="#Deep.Relationship.Queries">Deep Relationship Queries</a></li>
			<li><a href="#_related_object">Query Related Models (Existing Object)</a></li>
			<li><a href="#_join_field">Query Join Fields</a></li>
		</ul>
	</li>
	<li><a href="#Get.Advanced.Selection">Get (Advanced Selection)</a>
		<ul>
			<li><a href="#include_related">Including Related Columns</a></li>
			<li><a href="#Deep.Relationship.Include">Deep Relationship Queries</a></li>
			<li><a href="#include_related_count">Including the Number of Related Items</a></li>
			<li><a href="#include_join_fields">Including Join Fields</a></li>
		</ul>
	</li>
</ul>


<h2 id="Get.Advanced.Example">Example</h2>
<p>Let's go through an example to see the benefits.  Let's say we have a User model and a Group model.  A group can have many users but a user can only have one group.  Here's how you would look up all users belonging to the Moderator group without the advanced query:</p>
<pre>
<var></var><samp>// Create user object
</samp><var>$u </var><kbd>= new </kbd><var>User</var><kbd>();

</kbd><samp>// Get all users
</samp><var>$u</var><kbd>-&gt;</kbd><var><u>get</u></var><kbd>();

</kbd><samp>// Loop through all users
</samp><kbd>foreach (</kbd><var>$u</var> <kbd>as </kbd><var>$user</var><kbd>)
{
    </kbd><samp>// Get the current user's group
    </samp><var>$user</var><kbd>-&gt;</kbd><var>group</var><kbd>-&gt;</kbd><var><u>get</u></var><kbd>();

    </kbd><samp>// Check if user is related to the Moderator group
    </samp><kbd>if (</kbd><var>$user</var><kbd>-&gt;</kbd><var>group</var><kbd>-&gt;</kbd><var>name </var><kbd>== </kbd><dfn>'Moderator'</dfn><kbd>)
    {
        </kbd><samp>// ...
    </samp><kbd>}
}
</kbd>
</pre>

<p>Here's how you would do the above, but using an advanced query:</p>
<pre>
<var></var><samp>// Create user object
</samp><var>$u </var><kbd>= new </kbd><var>User</var><kbd>();

</kbd><samp>// Get users that are related to the Moderator group
</samp><var>$u</var><kbd>-&gt;</kbd><var>where_related_group</var><kbd>(</kbd><dfn>'name'</dfn><kbd>, </kbd><dfn>'Moderator'</dfn><kbd>)-&gt;</kbd><var><u>get</u></var><kbd>();

</kbd><samp>// ...</samp>
</pre>


<p>As you can see, it's a big time saver but not just in the amount of code you write, but also in the number of database queries and overall processing time.</p>


<h2 id="Supported.Query.Clauses">Supported Query Clauses</h2>

<p>The following are the normal query clauses that you can use in the advanced queries. One of these must replace <var><i>{query}</i></var> in the methods below:</p>

<ul>
	<li><var><i>where</i></var></li>
	<li><var><i>or_where</i></var></li>
	<li><var><i>where_in</i></var></li>
	<li><var><i>or_where_in</i></var></li>
	<li><var><i>where_not_in</i></var></li>
	<li><var><i>or_where_not_in</i></var></li>
	<li><var><i>where_between</i></var> - Requires two values to be specified</li>
	<li><var><i>or_where_between</i></var> - Requires two values to be specified</li>
	<li><var><i>where_not_between</i></var> - Requires two values to be specified</li>
	<li><var><i>or_where_not_between</i></var> - Requires two values to be specified</li>
	<li><var><i>like</i></var></li>
	<li><var><i>not_like</i></var></li>
	<li><var><i>or_like</i></var></li>
	<li><var><i>or_not_like</i></var></li>
	<li><var><i>ilike</i></var></li>
	<li><var><i>not_ilike</i></var></li>
	<li><var><i>or_ilike</i></var></li>
	<li><var><i>or_not_ilike</i></var></li>
	<li><var><i>group_by</i></var> - For grouping results</li>
	<li><var><i>having</i></var> - For grouping results</li>
	<li><var><i>or_having</i></var> - For grouping results</li>
	<li><var><i>order_by</i></var> - For ordering the results</li>
</ul>


<h2 id="_related_model">$object->{query}_related_{model}($field, $value);</h2>

<p>There are a number of ways you can use these advanced queries, and this is the first usage format.  All examples are done with the User and Group objects scenario.</p>

<ul>
	<li><var><i>{query}</i></var> - Replace with supported query type.</li>
	<li><var><s>{model}</s></var> - Replace with related model name OR the <b>relationship key</b> for advanced relationships.</li>
	<li><dfn>$field</dfn> - First parameter for chosen query type.</li>
	<li><dfn>$value</dfn> - Second parameter for chosen query type.</li>
</ul>

<p>Here's an example using the <var><i>where</i></var> query:</p>
<pre>
<var></var><samp>// Create user
</samp><var>$u </var><kbd>= new </kbd><var>User</var><kbd>();

</kbd><samp>// Get all users relating to the Moderator group (goes by 'group', 'name', 'Moderator')
</samp><var>$u</var><kbd>-&gt;</kbd><var><i>where</i><u>_related_</u><s>group</s></var><kbd>(</kbd><dfn>'name'</dfn><kbd>, </kbd><dfn>'Moderator'</dfn><kbd>)-&gt;</kbd><var><u>get</u></var><kbd>();</kbd>
</pre>


<h2 id="_related">$object->{query}_related($model, $field, $value);</h2>

<p>Alternatively, rather than specifying the related model as part of the method, you could instead supply it as the first parameter.  You must use this format when querying deep relationships.</p>

<ul>
	<li><var><i>{query}</i></var> - Replace with supported query type.</li>
	<li><var><s>$model</s></var> - Supply related model name OR the <b>relationship key</b> for advanced relationships.  Also accepts deep relationships.</li>
	<li><dfn>$field</dfn> - First parameter for chosen query type.</li>
	<li><dfn>$value</dfn> - Second parameter for chosen query type.</li>
</ul>

<p>Here's an example using the <var><i>where</i></var> query:</p>
<pre>
<var></var><samp>// Create user
</samp><var>$u </var><kbd>= new </kbd><var>User</var><kbd>();

</kbd><samp>// Get all users relating to the Moderator group (goes by 'group', 'name', 'Moderator')
</samp><var>$u</var><kbd>-&gt;</kbd><var><i>where</i><u>_related</u></var><kbd>(</kbd><var><s>'group'</s></var><kbd>, </kbd><dfn>'name'</dfn><kbd>, </kbd><dfn>'Moderator'</dfn><kbd>)-&gt;</kbd><var><u>get</u></var><kbd>();</kbd>
</pre>

<div class="note">
	<p>
		If the query clause is <var>where</var>, and <dfn>$value</dfn> is a Datamapper object, Datamapper will convert the query into <var>where_in</var> clause and use the id's of the results stored in the object as parameters.
	</p>
</div>

<p>Here's an example of such a query:</p>
<pre>
<var></var><samp>// Get a list of all male users
</samp><var>$u </var><kbd>= new </kbd><var>User</var><kbd>();
</kbd><samp>$u</var><kbd>-&gt;</kbd><var><i>where</i><kbd>(</kbd><var><s>'gender'</s></var><kbd>, </kbd><dfn>'M'</dfn><kbd>)-&gt;</kbd><var><u>get</u></var><kbd>();

</kbd><samp>// Get all the messages these males have posted
</samp><var>$p </var><kbd>= new </kbd><var>Post</var><kbd>();
</samp><var>$p</var><kbd>-&gt;</kbd><var><i>where</i><u>_related</u></var><kbd>(</kbd><var><s>'user'</s></var><kbd>, </kbd><dfn>'id'</dfn><kbd>, </kbd><var>$u</var><kbd>)-&gt;</kbd><var><u>get</u></var><kbd>();</kbd>
</pre>


<h2 id="Deep.Relationship.Queries">Deep Relationship Queries</h2>
<p>This format also accepts <b>deep relationships</b>, so you can query objects that are indirectly related to the current object.</p>
<p>A deep relationships is simply the name of each related object, in order, separated by a forward slash (<tt>/</tt>).</p>
<p>Here's an example:</p>
<pre>
<var>$u </var><kbd>= new </kbd><var>User</var><kbd>();

</kbd><samp>// Get all users that are associated with a :
// -&gt; Project that have one or more ...
//   -&gt; Tasks whose ...
//     -&gt; Status is labeled 'completed'
</samp><var>$u</var><kbd>-&gt;</kbd><var><i>where</i><u>_related</u></var><kbd>(</kbd><var><s>'project/task/status'</s></var><kbd>, </kbd><dfn>'label'</dfn><kbd>, </kbd><dfn>'completed'</dfn><kbd>)-&gt;</kbd><var><u>get</u></var><kbd>();</kbd>
</pre>

<p>The generated query for this simple request is surprisingly complex!</p>
<pre>
<var><kbd>SELECT</kbd> `users`<kbd>.</kbd><dfn>*</dfn>
<kbd>FROM</kbd> `users`
<kbd>LEFT OUTER JOIN</kbd> `projects_users` <kbd>as</kbd> `projects_users` <kbd>ON</kbd> `projects_users`<kbd>.</kbd>`user_id` <kbd>=</kbd> `users`<kbd>.</kbd>`id`
<kbd>LEFT OUTER JOIN</kbd> `projects` <kbd>as</kbd> `projects` <kbd>ON</kbd> `projects_users`<kbd>.</kbd>`project_id` <kbd>=</kbd> `project`<kbd>.</kbd>`id`
<kbd>LEFT OUTER JOIN</kbd> `tasks` <kbd>as</kbd> `project_tasks` <kbd>ON</kbd> `project_tasks`<kbd>.</kbd>`project_id` <kbd>=</kbd> `projects`<kbd>.</kbd>`id`
<kbd>LEFT OUTER JOIN</kbd> `statuses` <kbd>as</kbd> `project_task_statuses` <kbd>ON</kbd> `project_tasks`<kbd>.</kbd>`status_id` <kbd>=</kbd> `project_task_statuses`<kbd>.</kbd>`id`
<kbd>WHERE</kbd> `project_task_statuses`<kbd>.</kbd>`label` <kbd>=</kbd> <dfn>'completed'</dfn></var>
</pre>

<div class="note">
	<p>For deep queries as the example above, you should almost always call <var><u>distinct</u></var>, to ensure that the database doesn't return duplicate rows.</p>
</div>


<h2 id="_related_object">$object->{query}_related($related_object, $field, $value);</h2>

<ul>
	<li><var><i>{query}</i></var> - Replace with supported query type.</li>
	<li><var><s>$related_object</s></var> - Supply related object (may not work for advanced relationships).</li>
	<li><strong>Optional:</strong> <dfn>$field</dfn> - First parameter for chosen query type.</li>
	<li><strong>Optional:</strong> <dfn>$value</dfn> - Second parameter for chosen query type.</li>
</ul>

<p class="note">Both the <dfn>$field</dfn> and <dfn>$value</dfn> parameters are optional if the <var><s>$related_object</s></var> contains a valid <strong>id</strong>.</p>

<p>Here's an example using the <var><i>where</i></var> query:</p>
<pre>
<samp>// Create and get the Moderator group
</samp><var>$g </var><kbd>= new </kbd><var>Group</var><kbd>();
</kbd><var>$g</var><kbd>-&gt;</kbd><var><u>get_by_name</u></var><kbd>(</kbd><dfn>'Moderator'</dfn><kbd>);

</kbd><samp>// Create user
</samp><var>$u </var><kbd>= new </kbd><var>User</var><kbd>();

</kbd><samp>// Get all users relating to the Moderator group (goes by 'group', 'id', $g-&gt;id)
</samp><var>$u</var><kbd>-&gt;</kbd><var><i>where</i><u>_related</u></var><kbd>(</kbd><var><s>$g</s></var><kbd>)-&gt;</kbd><var><u>get</u></var><kbd>();</kbd>
</pre>

<p>Here's a similar way of doing the above, but with an unpopulated related object (no id):</p>
<pre>
<samp>// Create and get the Moderator group
</samp><var>$g </var><kbd>= new </kbd><var>Group</var><kbd>();

</kbd><samp>// Create user
</samp><var>$u </var><kbd>= new </kbd><var>User</var><kbd>();

</kbd><samp>// Get all users relating to the Moderator group (goes by 'group', 'name', 'Moderator')
</samp><var>$u</var><kbd>-&gt;</kbd><var><i>where</i><u>_related</u></var><kbd>(</kbd><var><s>$g</s></var><kbd>, </kbd><dfn>'name'</dfn><kbd>, </kbd><dfn>'Moderator'</dfn><kbd>)-&gt;</kbd><var><u>get</u></var><kbd>();</kbd>
</pre>


<p>Which of the available usage formats you use will depend on your personal preference, although you should be consistent with your choice.  It also might depend on whether you have a related object already available to use.</p>

<p class="note">To find records that do not have a relation, specify '<strong>id</strong>' as the <dfn>$field</dfn> and <strong>NULL</strong> as the <dfn>$value</dfn>.</p>

<h2 id="_join_field">$object->{query}_join_field($model, $field, $value);</h2>

<p>This method allows you to query extra columns on a join table.</p>

<ul>
	<li><var><i>{query}</i></var> - Replace with supported query type.</li>
	<li><var><s>$model</s></var> - A related model name OR the <b>relationship key</b> for advanced relationships, or a related object.</li>
	<li><dfn>$field</dfn> - First parameter for chosen query type.</li>
	<li><dfn>$value</dfn> - Second parameter for chosen query type.</li>
</ul>

<div class="note">
	<p>You always have to include <strong>$related_field</strong>, even if the query is coming from a relationship.  In other words, you’ll often write code like this:</p>
	<pre><var>$user</var><kbd>-&gt;</kbd><var>alarm</var><kbd>-&gt;</kbd><var><i>where</i><u>_join_field</u></var><kbd>(</kbd><var><s>$user</s></var><kbd>, </kbd><dfn>'wasfired'</dfn><kbd>, </kbd><var><dfn>FALSE</dfn></var><kbd>)-&gt;</kbd><var><u>get</u></var><kbd>();</kbd></pre>
</div>

<p>Here's an example using the <var><i>where</i></var> query:</p>
<pre>
<samp>// Create alarm
</samp><var>$alarm </var><kbd>= new </kbd><var>Alarm</var><kbd>();

</kbd><samp>// Get all alarms that have not been fired for one or more users
</samp><var>$alarm</var><kbd>-&gt;</kbd><var><i>where</i><u>_join_field</u></var><kbd>(</kbd><var><s>'user'</s></var><kbd>, </kbd><dfn>'wasfired'</dfn><kbd>, </kbd><var><dfn>FALSE</dfn></var><kbd>)-&gt;</kbd><var><u>get</u></var><kbd>();</kbd>
</pre>


<p>See <a href="joinfields.html">Working with Join Fields</a> for more details.</p>


<p>&nbsp;</p>


<h1 id="Get.Advanced.Selection">Get (Advanced Selection)</h1>
<p>You can also perform some more advanced options when selecting columns, by including columns from related models or from the join table.</p>

<h2 id="include_related">$object->include_related($model, $fields = NULL, $prefix = TRUE, $instantiate = FALSE)</h2>
<p>Includes the all or some of the columns from a related object.  By default, this method adds a prefix based on $model to every column.  If for some reason the included column overlaps with a field already in the $object, that column is skipped.  This method can significantly reduce your query overhead.</p>
<ul>
	<li><var><s>$model</s></var> - A related model name OR the <b>relationship key</b> for advanced relationships, or a related object.  Also accepts deep relationships.</li>
	<li><dfn>$fields</dfn> - NULL or '*' to include all columns.  To specify a subset of columns (recommended), replace with a single value, or an array of column names.</li>
	<li><dfn>$prefix</dfn> - If <dfn>TRUE</dfn>, prepend <dfn>"{<var>$model</var>}_"</dfn> to the column names.  If <dfn>FALSE</dfn>, don't prepend anything.  If any string, prepend <dfn>"{<var>$prefix</var>}_"</dfn> to each column.</li>
	<li><dfn>$instantiate</dfn> - If <dfn>TRUE</dfn>, then actual objects are instantiated and populated with the columns automatically.</li>
</ul>

<p>Here's an example:</p>
<pre>
<samp>// Create User
</samp><var>$u </var><kbd>= new </kbd><var>User</var><kbd>();

</kbd><samp>// add the group id and name to all users returned
</samp><var>$u</var><kbd>-&gt;</kbd><var><u>include_related</u></var><kbd>(</kbd><var><s>'group'</s></var><kbd>, array(</kbd><dfn>'id'</dfn><kbd>, </kbd><dfn>'name'</dfn><kbd>))-&gt;</kbd><var><u>get</u></var><kbd>();

foreach(</kbd><var>$u</var> <kbd>as </kbd><var>$user</var><kbd>) {
    echo(</kbd><dfn>"<kbd>{</kbd><var>$user</var><kbd>-&gt;</kbd><var>group_name</var><kbd>}</kbd> (<kbd>{</kbd><var>$user</var><kbd>-&gt;</kbd><var>group_id</var><kbd>}</kbd>)\n"</dfn><kbd>);
}</kbd>
</pre>

<p>If you use <dfn>$instantiate</dfn>, then you can use the related objects directly, like so:</p>
<pre>
<samp>// Create User
</samp><var>$u </var><kbd>= new </kbd><var>User</var><kbd>();

</kbd><samp>// add the group id and name to all users returned
</samp><var>$u</var><kbd>-&gt;</kbd><var><u>include_related</u></var><kbd>(</kbd><dfn>'group'</dfn><kbd>, array(</kbd><dfn>'id'</dfn><kbd>, </kbd><dfn>'name'</dfn><kbd>), </kbd><var><dfn>TRUE</dfn></var><kbd>, </kbd><var><dfn>TRUE</dfn></var><kbd>)-&gt;</kbd><var><u>get</u></var><kbd>();

foreach(</kbd><var>$u</var> <kbd>as </kbd><var>$user</var><kbd>) {
    echo(</kbd><dfn>"{</kbd><var>$user</var><kbd>-&gt;</kbd><var>group</var><kbd>-&gt;</kbd><var>name</var><kbd>}</kbd> (<kbd>{</kbd><var>$user</var><kbd>-&gt;</kbd><var>group</var><kbd>-&gt;</kbd><var>id</var><kbd>})\n"</dfn><kbd>);
}</kbd>
</pre>

<p class="important"><strong><em>Important:</em></strong> This method creates a full join on both tables. Make sure to use the appropriate where clauses, and/or use DISTINCT, to limit the number of rows in the result!</p>

<h2 id="Deep.Relationship.Include">Including Fields from Deep Relationships</h2>
<p>This method also supports deep relationships.  You can only include columns from objects that are related by single relationships all the way.  The default column prefix for deep relationships is to replace all forward slashes with underscores.  You can still override this to be whatever you want.</p>
<p>A deep relationship is simply the name of each related object, in order, separated by a forward slash (<tt>/</tt>).</p>
<p>Here's an example:</p>
<pre>
<samp>// Create Post
</samp><var>$p </var><kbd>= new </kbd><var>Post</var><kbd>();

</kbd><samp>// Include the user's name in the result:
</samp><var>$p</var><kbd>-&gt;</kbd><var><u>include_related</u></var><kbd>(</kbd><var><s>'user'</s></var><kbd>, </kbd><dfn>'name'</dfn><kbd>);
</kbd><samp>// include the user's group's name in the result:
</samp><var>$p</var><kbd>-&gt;</kbd><var><u>include_related</u></var><kbd>(</kbd><var><s>'user/group'</s></var><kbd>, </kbd><dfn>'name'</dfn><kbd>);
</kbd><var>$p</var><kbd>-&gt;</kbd><var><u>get</u></var><kbd>();

foreach(</kbd><var>$p</var> <kbd>as </kbd><var>$post</var><kbd>) {
    echo(</kbd><dfn>"<kbd>{</kbd><var>$post</var><kbd>-&gt;</kbd><var>user_name</var><kbd>}</kbd> (<kbd>{</kbd><var>$post</var><kbd>-&gt;</kbd><var>user_group_name</var><kbd>}</kbd>)\n"</dfn><kbd>);
}</kbd>
</pre>

<p class="note">At this time, deep relationships <strong>do not support instatiation</strong>.</p>

<h2 id="include_related_count">$object->include_related_count($related_field, $alias = NULL)</h2>
<p>
	This method can be used to include the number of related items.
	By default, this is stored in the alias <strong>{$related_field}_count</strong>, but you can override this alias using the second argument.
	This method also supports using deep relationships, although the operation may fail for relationships that are not has_one (excluding, of course, the last).
</p>
<p class="note">This method requires the use of <a href="subqueries.html">subqueries</a>.</p>

<p>Example:</p>
<pre>
<var>$groups </var><kbd>= new </kbd><var>Group</var><kbd>();

</kbd><var>$groups</var><kbd>-&gt;</kbd><var><u>include_related_count</u></var><kbd>(</kbd><dfn>'user'</dfn><kbd>)-&gt;</kbd><var><u>get</u></var><kbd>();

foreach(</kbd><var>$groups </var><kbd>as </kbd><var>$group</var><kbd>) {
    echo(</kbd><dfn>"The group {</dfn><var>$group</var><kbd>-&gt;</kbd><var>name</var><dfn>} has {</dfn><var>$group</var><kbd>-&gt;</kbd><var>user_count</var><dfn>} User(s)\n"</dfn><kbd>);
}</kbd>
</pre>

<h2 id="include_join_fields">$object->include_join_fields()</h2>
<p>There are no options for this method.  Set it right <b>before</b> adding a relationship.  You can either use it before a <strong>{$query}_related_{$model}</strong>, or before calling <strong>get()</strong> on a related item.  All fields on the table that are not part of the relationship are included, and are prepended with <b>"join_"</b>.</p>
<p class="note">This method may return unexpected results or throw errors with deep relationships.</p>

<p>Usage:</p>
<pre>
<samp>// Create User
</samp><var>$u </var><kbd>= new </kbd><var>User</var><kbd>();
</kbd><var>$u</var><kbd>-&gt;</kbd><var><u>get_by_id</u></var><kbd>(</kbd><var>$userid</var><kbd>);

</kbd><samp>// get all alarms for this user, and include the extra 'wasfired' field
</samp><var>$u</var><kbd>-&gt;</kbd><var>alarm</var><kbd>-&gt;</kbd><var><u>include_join_fields</u></var><kbd>()-&gt;</kbd><var><u>get</u></var><kbd>();

foreach(</kbd><var>$u</var><kbd>-&gt;</kbd><var>alarm</var> <kbd>as </kbd><var>$alarm</var><kbd>) {
    if(</kbd><var>$alarm</var><kbd>-&gt;</kbd><var>join_wasfired</var><kbd>) {
        echo(</kbd><dfn>"<kbd>{</kbd><var>$alarm</var><kbd>-&gt;</kbd><var>name</var><kbd>}</kbd> was fired\n"</dfn><kbd>);
    } else {
        echo(</kbd><dfn>"<kbd>{</kbd><var>$alarm</var><kbd>-&gt;</kbd><var>name</var><kbd>}</kbd> was NOT fired\n"</dfn><kbd>);
    }
}</kbd>
</pre>

<p>See <a href="joinfields.html">Working with Join Fields</a> for more details.</p>

</div>
<!-- END CONTENT -->


<div id="footer">
<p>
<span id="footer_previous">Previous Topic:&nbsp;&nbsp;<a href=""></a>
&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;</span>
<a href="#top">Top of Page</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
<a href="../index.html">User Guide Home</a>
<span id="footer_next">&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
Next Topic:&nbsp;&nbsp;<a href=""></a></span>
</p>
<div id="copyrights">
<p><a href="/">Datamapper ORM</a> &nbsp;&middot;&nbsp; Copyright &copy; 2010-2011 &nbsp;&middot;&nbsp; Harro "WanWizard" Verton</p>
<p><a href="license.html">Other License Information</a></p>
</div>
</div>

<script type="text/javascript" src="../js/mootools.js"></script>
<script type="text/javascript" src="../js/menu.js"></script>
<script type="text/javascript">
<!--
	window.addEvent('domready', function() {

		// Create Menu
		var menu = new Menu({
			basepath: '../',
			pagespath: ''
		});

	});
//-->
</script>
</body>
</html>
